﻿using MaiPlanServer.IServices.Production;
using MaiPlanServer.Model;
using MaiPlanServer.Utility;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MaiPlanServer.API.Controllers.Production
{/// <summary>
/// 生产计划
/// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class ProductionPlanController : ControllerBase
    {
        public ProductionPlanController(IProductionPlanServices db)
        {
            Db = db;
        }
        public IProductionPlanServices Db { get; }
        /// <summary>
        /// 获取生产计划数据
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        /// <param name="PageSize">显示条数</param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<IActionResult> GetPro_Workorders(int PageIndex, int PageSize, string workorder_code, string workorder_name, string source_code, string product_code, string product_name, string client_code, string client_name, string request_date)
        {
            try
            {

                var list = await Db.GetPro_Workorders(PageIndex, PageSize, workorder_code, workorder_name, source_code, product_code, product_name, client_code, client_name, request_date);

                var count = await Db.GetPro_WorkordersCount(workorder_code, workorder_name, source_code, product_code, product_name, client_code, client_name, request_date);


                return Ok(BaseState.CreateInstance(200, "请求成功", list, count));
            }
            catch (Exception ex)
            {
            }

            return Ok(BaseState.CreateInstance(BaseState.RequestError, "服务器异常"));
        }
        /// <summary>
        /// 获取订单数据
        /// </summary>
        /// <param name="id">订单Id</param>
        /// <returns></returns>
        [HttpGet("GetProWorkordersDto")]
        public async Task<IActionResult> GetPro_WorkordersDto(string id)
        {
            try
            {
                var data = await Db.GetPro_WorkordersDto(id);

                return Ok(BaseState.CreateInstance(200, "请求成功",data.ToArray()));
            }
            catch (Exception ex)
            {
            }

            return Ok(BaseState.CreateInstance(BaseState.RequestError, "服务器异常"));
        }
    }
}
